<%layout("/eova/layout/default.html",{'title' : '导入数据'}){%>
<body>
  <div style="padding: 5px;font-size: 10px;">
    新增导入：<br />
    如果导入的Excel表格中没有主键列，则自动新增所有行的数据。<br />
    更新导入：<br />
    如果导入的Excel表格中存在主键列，则自动根据每行主键更新相关数据。<br />
  </div>

  <div style="padding: 5px;">
    <form
      target="ajaxUpload"
      id="importForm"
      action="/single_grid/doImportXls/${menuCode}"
      method="POST"
      enctype="multipart/form-data"
    >
      <input
        type="file"
        id="upfile"
        name="upfile"
        value="上传"
        formaction="importForm"
        placeholder="请选择要上传的xls文件"
        accept=".xls"
        style="height: 100%"
      />
    </form>
  </div>

  <iframe name="ajaxUpload" style="display:none"> </iframe>
  <script type="text/javascript">
    var extArray = new Array(".xls")
    var $ppjq
    var $pwidget
    function limit(file) {
      var allowSubmit = false
      if (!file) {
        $.slideMsg("请选择一个Excel文件!", $ppjq)
        return false
      }
      while (file.indexOf("\\") != -1) {
        file = file.slice(file.indexOf("\\") + 1)
      }
      var ext = file.slice(file.lastIndexOf(".")).toLowerCase()
      for (var i = 0; i < extArray.length; i++) {
        if (extArray[i] == ext) {
          allowSubmit = true
          break
        }
      }
      if (!allowSubmit) {
        alert("只能上传以下格式的文件:" + extArray.join("") + "\n请重新选择再上传.")
        return false
      }
      return true
    }

    var btnSaveCallback = function($dialog, $widget, $pjq) {
      $ppjq = $pjq
      $pwidget = $widget
      var $fm = $("#importForm")
      var $file = $("#upfile")
      if (limit($file.val())) {
        var $btn = $pjq("#eovaImport")
        $btn.linkbutton({ disabled: true })
        var i = 3
        function count() {
          i--
          if (i == 0) {
            $btn.linkbutton({ disabled: false })
            return
          }
          setTimeout(function() {
            count()
          }, 1000)
        }
        count()

        $fm.submit()
      }
    }

    // 上传回调:IFrame Ajax上传
    var callback = function(msg, success) {
      if (success) {
        $.slideMsg(msg, $ppjq)
      } else {
        $.alert($ppjq, msg)
      }
      $.widgetReLoad($pwidget)
      $ppjq("#import_dialog").dialog("destroy")
    }
  </script>
</body>
<%}%>
